<?php
	
	$user = $controller->getCurrentUser();
	
	//on verifie les permissions
	if ($user->isAllowedTo(GRADE_MOD_BOOK))
	{    
		$albumId = $request->getParam('aid');
		if ($request->getParam('collapseNew'))
			$controller->setVar('collapseNew','collapsed');
		else
			$controller->setVar('collapseNew','');
			 
		if ($albumId) //si on soumet un album
		{
			$editionsList = edition::getEditionsList($albumId);
			$publishersList = publisher::getList();
			$seriesList = serie::getList();
			$authorsList = author::getList();
			$authorsBook = author::getAuthorsByBook($albumId);
				
			$controller->setVar('authorsBook',$authorsBook);
			$controller->setVar('albumId',$albumId);
			$controller->setVar('editionsList',$editionsList);
			$controller->setVar('publishersList',$publishersList);
			$controller->setVar('seriesList',$seriesList);
			$controller->setVar('authorsList',$authorsList);
			$controller->setVar('years',generateListYears());
			$controller->render('addBook');
		}
		else 
		{
			$editionSubmitted = $request->getParam('edSubmitted');
			if (!$editionSubmitted)
			{	
				$albumsList = album::getAlbumsList();
				$controller->setVar('albumsList',$albumsList);
				$publishersList = publisher::getList();
				$seriesList = serie::getList();
				$authorsList = author::getList();
				$controller->setVar('publishersList',$publishersList);
				$controller->setVar('seriesList',$seriesList);
				$controller->setVar('authorsList',$authorsList);
				$controller->setVar('years',generateListYears());
				$controller->render('addBook');
			}
			else
			{
				$editionId = $request->getParam('editionSelect');
				if ($editionId)
				{
					$controller->setVar('editionId',$editionId);
					$controller->forward('addBookSecondWay');
				}
				else
				{
					$controller->forward('addBookThirdWay');	
				}
			}
		}
	}
	else
		$controller->render('errorRights');
  
	
?>
